package com.yhn.init.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yhn.init.common.BaseResponse;
import com.yhn.init.common.DeleteRequest;
import com.yhn.init.common.ResultUtils;
import com.yhn.init.model.dto.role.RoleAddRequest;
import com.yhn.init.model.dto.role.RoleQueryRequest;
import com.yhn.init.model.dto.role.RoleUpdateRequest;
import com.yhn.init.model.vo.RoleVO;
import com.yhn.init.service.RoleService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 * 角色
 *
 * @author yhnyhn123
 * @email 2236751002@qq.com
 * @date 2024-03-08 20:36:42
 */
@RestController
@RequestMapping("/role")
public class RoleController {

    @Resource
    private RoleService roleService;

    /**
     * 列表,分页
     */
    @GetMapping("/list")
    //@SaCheckPermissions("furniture/role/list")
    public BaseResponse<Page<RoleVO>> listByPage(@RequestBody RoleQueryRequest roleQueryRequest) {
        Page<RoleVO> page = roleService.queryPage(roleQueryRequest);
        return ResultUtils.success(page);
    }


    /**
     * 获取单个信息
     */
    @GetMapping("/info/{id}")
    //@SaCheckPermissions("furniture/role/info")
    public BaseResponse<RoleVO> getInfoById(@PathVariable("id") Long id) {
        RoleVO role = roleService.getInfoById(id);

        return ResultUtils.success(role);
    }


    /**
     * 保存
     */
    @PostMapping("/save")
    // @SaCheckPermissions("furniture/role/save")
    public BaseResponse<Long> save(@RequestBody RoleAddRequest roleAddRequest) {
        Long newId = roleService.saveRole(roleAddRequest);

        return ResultUtils.success(newId);
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    //@SaCheckPermissions("furniture/role/update")
    public BaseResponse<Boolean> update(@RequestBody RoleUpdateRequest roleUpdateRequest) {
        boolean result = roleService.updateRole(roleUpdateRequest);

        return ResultUtils.success(result);
    }


    /**
     * 删除
     */
    @PostMapping("/delete")
    //@SaCheckPermissions("furniture/role/delete")
    public BaseResponse<Boolean> delete(@RequestBody DeleteRequest deleteRequest) {
        boolean result = roleService.deleteById(deleteRequest);
        return ResultUtils.success(result);
    }

    /**
     * 批量删除
     */
    @PostMapping("/deleteBatch")
    //@SaCheckPermissions("furniture/role/delete")
    public BaseResponse<Boolean> deleteBatch(@RequestBody Long[] ids) {
        boolean result = roleService.deleteBatchByIds(ids);
        return ResultUtils.success(result);
    }
}
